package edu.colorado.cs.correll.cudroplet.shaperecognition;

import processing.core.PVector;

public class SimpleSimulation extends Simulation {
	
	public SimpleSimulation(ShapeRecognition shapeRecognition) {
		this.shapeRecognition = shapeRecognition;

		String[] shape_names = { "rectangle", "ellipse", "hexagon", "star",
				"polygon" };
		PVector[] sPos = new PVector[shape_names.length *2];
		PVector buf = new PVector(50, shapeRecognition.height/3);
		for(int i = 0; i < shape_names.length * 2; i++) {
			PVector p = new PVector((i%shape_names.length) * shapeRecognition.width/shape_names.length, (i/shape_names.length) * shapeRecognition.height/shape_names.length);
			sPos[i] = PVector.add(p, buf);
		}
		train = sPos[0].y;
		test = sPos[shape_names.length].y;
		
		testPlacedShapes = new PlacedShape[shape_names.length ];
		
		for (int i = 0; i < shape_names.length; i++) {
			testPlacedShapes[i] = new PlacedShape(shape_names[i], sPos[i]);
		}
		
		placedShapes = new PlacedShape[shape_names.length * 2];
		
		for(int i = 0; i < shape_names.length * 2; i++) {
			placedShapes[i] = new PlacedShape(shape_names[i%shape_names.length], sPos[i]);
		}
		
		envMap = new SimpleEnvironmentMap(shapeRecognition, placedShapes, shapeRecognition.width,
				shapeRecognition.height, 10);
		
		swarm = new SimpleSwarm(shapeRecognition, (SimpleEnvironmentMap) envMap);
	}

	@Override
	public void draw() {
		// draw the stuff we are picking off of
		envMap.draw();

		shapeRecognition.drawExclusions();

	    // get ready to pick
	    shapeRecognition.loadPixels();

	    // update based on picking information
	    for (int j = 0; j < RATE; j++) {
	    	swarm.update();
	    }

	    
	    
	    // draw the bodies of the robots. We don't pick off of this.
	    //shapeRecognition.drawBodies(true, false);
	    
	    //shapeRecognition.drawConvexHulls(true);
	    //shapeRecognition.drawAlphaShapes(true);
	}

}
